var website = "https://www.brookspest.com"; var findOriging = window.location.origin.toString(); var url1 = website; var url2 = findOriging; function getMainDomain(hostname) { // Split the hostname by dots let parts = hostname.split('.'); // If there are only two parts, it's already the main domain (e.g., example.com) // If there are more than two parts, remove the first part (subdomain) if (parts.length > 2) { parts.shift(); } // Join the remaining parts back together return parts.join('.'); } function areSameDomain(url1, url2) { try { // Create URL objects let parsedUrl1 = new URL(url1); let parsedUrl2 = new URL(url2); // Get the main domains let mainDomain1 = getMainDomain(parsedUrl1.hostname); let mainDomain2 = getMainDomain(parsedUrl2.hostname); //console.log("validUrl",mainDomain1); if(mainDomain1 === "s1-tastewp.com"){ return true; } // Compare the main domains return mainDomain1 === mainDomain2; } catch (error) { console.error('Invalid URL:', error); return false; } } if (areSameDomain(url1, url2)) { console.log('The URLs have the same main domain.'); } else { //check website here console.warn("Stopping script execution because origin matches"); //window.stop(); throw new Error("Stopping script execution because origin matches"); } var scriptElement = document.createElement("script"); var scriptCode = `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-KCX3RRS');` scriptElement.textContent = scriptCode; document.body.appendChild(scriptElement); var noscriptElement = document.createElement("noscript"); var noscriptCode = ``; noscriptElement.innerHTML = noscriptCode; document.body.appendChild(noscriptElement);